package com.hehe.Repository;


import com.hehe.POJO.Photo;
import jakarta.persistence.LockModeType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface PhotoRepository extends JpaRepository<Photo, Long> {


    @Modifying
    @Transactional
    @Query("UPDATE Photo p SET p.collect = p.collect + :add_mins  WHERE p.id = :photoId")
    int incrementCollectCount(Integer add_mins, long photoId);  // +1  or  -1

    //    模糊查询
    @Query("SELECT p FROM Photo p WHERE p.title LIKE %:title%")
    Page<Photo> findByTitleContaining(String title, Pageable pageable);

    @Query("SELECT p.netdiskLink FROM Photo p WHERE p.id = :photoId")
    String findNetdiskLinkByPhotoId(Integer photoId);

}
